<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>2.详聊v-for</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo">
      <h2>遍历数组（用的多）</h2>
      <ul>
        <li v-for="(p,index) in persons" :key="p.id">
          {{p.name}}：{{p.description}} --- {{index}}
        </li>
      </ul>
      <hr>

      <h2>遍历对象（用的多）</h2>
      <ul>
        <li v-for="(value,key,index) in car" :key="key">
          {{value}} - {{key}} - {{index}}
        </li>
      </ul>
      <hr>

      <h2>遍历字符串（用的少）</h2>
      <ul>
        <li v-for="(char,index) in message" :key="index">
          {{char}} - {{index}}
        </li>
      </ul>
      <hr>

      <h2>遍历指定次数（用的多）</h2>
      <ul>
        <li v-for="(number,index) in 100">
          {{number}} - {{index}}
        </li>
      </ul>
      <hr>

      <h2>v-for很健壮，如下写法均不会报错</h2>
      <!-- <h4 v-for="a in null">你好</h4> -->
      <!-- <h4 v-for="a in undefined">你好</h4> -->
      <!-- <h4 v-for="a in true">你好</h4> -->
      <!-- <h4 v-for="a in ''">你好</h4> -->

    </div>

    <script type="text/javascript">
      new Vue({
        el:'#demo',
        data:{
          persons:[
            {id:'hfi7esytf8wh31',name:'晶哥',description:'红浪漫终身会员！'},
            {id:'hfi7esytf8wh32',name:'强哥',description:'抽烟只抽中华！'},
            {id:'hfi7esytf8wh33',name:'天禹',description:'这是一个照片骗子'}
          ],
          car:{
            name:'特斯拉',
            color:'红色'
          },
          message:'你好啊！',
          number:10
        }
      })
    </script>
  </body>
</html>